namespace Creek.UI.Tabstrip.Control
{
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;

    internal class FATabStripMenuGlyph
    {
        #region Fields

        private readonly ToolStripProfessionalRenderer renderer;

        private Rectangle glyphRect = Rectangle.Empty;

        private bool isMouseOver;

        #endregion

        #region Props

        public bool IsMouseOver
        {
            get
            {
                return this.isMouseOver;
            }
            set
            {
                this.isMouseOver = value;
            }
        }

        public Rectangle Bounds
        {
            get
            {
                return this.glyphRect;
            }
            set
            {
                this.glyphRect = value;
            }
        }

        #endregion

        #region Ctor

        internal FATabStripMenuGlyph(ToolStripProfessionalRenderer renderer)
        {
            this.renderer = renderer;
        }

        #endregion

        #region Methods

        public void DrawGlyph(Graphics g)
        {
            if (this.isMouseOver)
            {
                Color fill = this.renderer.ColorTable.ButtonSelectedHighlight;
                    //Color.FromArgb(35, SystemColors.Highlight);
                g.FillRectangle(new SolidBrush(fill), this.glyphRect);
                Rectangle borderRect = this.glyphRect;

                borderRect.Width--;
                borderRect.Height--;

                g.DrawRectangle(SystemPens.Highlight, borderRect);
            }

            SmoothingMode bak = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.Default;

            using (var pen = new Pen(Color.Black))
            {
                pen.Width = 2;

                g.DrawLine(
                    pen,
                    new Point(this.glyphRect.Left + (this.glyphRect.Width / 3) - 2, this.glyphRect.Height / 2 - 1),
                    new Point(this.glyphRect.Right - (this.glyphRect.Width / 3), this.glyphRect.Height / 2 - 1));
            }

            g.FillPolygon(
                Brushes.Black,
                new[]
                    {
                        new Point(this.glyphRect.Left + (this.glyphRect.Width / 3) - 2, this.glyphRect.Height / 2 + 2),
                        new Point(this.glyphRect.Right - (this.glyphRect.Width / 3), this.glyphRect.Height / 2 + 2),
                        new Point(this.glyphRect.Left + this.glyphRect.Width / 2 - 1, this.glyphRect.Bottom - 4)
                    });

            g.SmoothingMode = bak;
        }

        #endregion
    }
}